<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //声明一个字符串
        // let str = '<a href="http://www.baidu.com">百度</a>'

        // //提取 url 与 标签文本
        // const reg = /<a href="(.*)>(.*)<\/a>/;

        // //执行
        // const result = reg.exec(str)
        // console.log(result[1]);
        // console.log(result[2]);

        let str = '<a href="http://www.baidu.com">百度</a>'
        const reg = /<a href="(?<url>.*)>(?<text>.*)<\/a>/;
            //reg.exec()查找字符串中所有敏感词的内容和位置的函数。找到一个敏感词，就会返回一个数组：
        const result = reg.exec(str)
        console.log(result);
        console.log(result.groups.url);
        console.log(result.groups.text);

    </script>

</body>
</html>